package yf.mall.dysdk.utils;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yf.utils.HttpTookit;
import okhttp3.HttpUrl;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import yf.mall.dysdk.config.CommConstants;
import yf.mall.dysdk.model.user.DyFullUserInfo;
import yf.mall.dysdk.model.common.DyResponse;
import yf.mall.dysdk.model.user.UserResponse;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Date;

/**
 * @author yxmds
 */
public final class DyUtil {

    /**
     * 判断是否失效
     *
     * @param begin     生效开始时间
     * @param expiresIn 有效秒数
     * @return
     */
    public static boolean isExpired(Date begin, int expiresIn) {
        return DateUtils.addSeconds(begin, expiresIn).compareTo(new Date()) <= 0;
    }






    public static String encode(String input) {
        byte[] encodedBytes = Base64.getUrlEncoder().encode(input.getBytes(StandardCharsets.UTF_8));
        return new String(encodedBytes, StandardCharsets.UTF_8);
    }

    public static String decode(String input) {
        byte[] decodedBytes = Base64.getUrlDecoder().decode(input.getBytes(StandardCharsets.UTF_8));
        return new String(decodedBytes, StandardCharsets.UTF_8);
    }
}
